Generally, multithreaded (MT) programs based on pthreads have considerably more overhead than single threaded (ST) programs due to synchronization requirements in standard threaded library routines during run-time. This overhead can significantly affect the performance of MT programs when they are used in an ST program mode.
One current technique addresses this problem by including an “MT” option that does not create multiple threads in the MT programs that uses pthread library calls and only operates in the ST program mode during run time. Another current technique solves the MT overhead problem for the ST programs that has been optimized by compilers to run like the MT programs by marking MT regions through pthread autoparallelizations. Generally, such converted MT programs have well-defined MT regions since compiler decides when the ST program can begin and end to run as an MT program. This is generally accomplished by exporting interfaces from libpthreads for communicating the beginning and end of ST program mode to the libpthreads. Generally, the libpthreads use this information to decide whether to use a heavy weight (HW) synchronization or a light weight (LW) synchronization to improve performance.
However, the above techniques do not address the general problem of significant overhead created in the MT programs that alternate between the MT and ST program modes. Further, the current techniques cannot address the overhead problem in the MT programs when the existing legacy auto-parallelized/open market partition (MP) applications are created using older compilers which do not have the ability to mark when an MT program can begin and end, to run as an ST program. The above techniques address only one way first time switchover from the ST to MT program mode or vice versa and for subsequent threads, they continue to pay the excessive synchronization overhead.
There are many MT programs that run in the ST program mode most of the time and run on the MT program mode briefly, only to handle some service requests or perform certain compute intensive tasks. In such scenarios, these programs suffer from significant performance overhead due to the HW synchronization requirements in the standard threaded library routines. Typical example of such programs in producer/consumer type of applications includes Web applications which are usually written as threaded applications. In these applications, a main thread server waits for requests from a client and when one such request arrives, the main thread spawns a new thread (there can be many such requests). Upon completing the request the threads generally terminate and the main thread then waits again for another request from the clients. These MT programs are generally characterized by running most of the time in the ST program mode and only running in short periods in the MT program mode. However, such programs pay the penalty of performance overhead while using MT safe standard library routines for the entire time they are running. It can be seen that such programs suffer from excessive MT overhead due to high synchronization requirements that requires the pthread library calls to mutex_lock and mutex_unlock which use waiters list. The excessive MT overhead can be of the order of 2-3 times that of running an ST program without the MT overhead and this can significantly slowdown an application during run-time.
Other features of the present embodiments will be apparent from the accompanying drawings and from the detailed description that follows.